package com.xjob.controller;

import com.xjob.model.dto.XxlJobInfoDto;
import com.xjob.model.query.XxlJobQuery;
import com.xjob.util.XxlJobUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @description: xjob测试类
 * @author: xianggaoxiong
 * @create: 2020-05-21 17:32
 **/
@Controller
@RestController
@RequestMapping("/api/xxl/job")
public class XjobController {
    private static final String SUCCESS = "success";
    @Resource
    private XxlJobUtil jobUtil;

    @PostMapping("/add")
    public String add(@RequestBody XxlJobInfoDto xxlJobInfoDto) {
        return jobUtil.add(xxlJobInfoDto);
    }

    @PostMapping("/update")
    public String update(@RequestBody XxlJobInfoDto xxlJobInfoDto) {
        jobUtil.update(xxlJobInfoDto);
        return SUCCESS;
    }

    @DeleteMapping("/remove/{id}")
    public String remove(@PathVariable("id") int id) {
        jobUtil.remove(id);
        return SUCCESS;
    }

    @GetMapping("/start/{id}")
    public String start(@PathVariable("id") int id) {
        jobUtil.start(id);
        return SUCCESS;
    }

    @GetMapping("/pause/{id}")
    public String pause(@PathVariable("id") int id) {
        jobUtil.pause(id);
        return SUCCESS;
    }

    @PostMapping("/pageList")
    public Map<String, Object> pageList(@RequestBody XxlJobQuery query) {
        return jobUtil.pageList(query);
    }
}
